/**
 * Created with IntelliJ IDEA.
 * Description: leetcode.简单题.寻找数组的中心下标
 */

class Solution {
    public int pivotIndex(int[] nums) {
        //左边之和
        int sumLeft = 0;
        //总和
        int sum = 0;
        for (int i = 0; i < nums.length; i++) {
            sum += nums[i];
        }
        for(int i = 0; i < nums.length; i++){
            //求左边和
            if(i != 0){
                sumLeft += nums[i - 1];
            }
            //比较
            //sum - nums[i] - sumLeft 结果即是右边之和
            if(sumLeft == (sum - nums[i] - sumLeft)){
                return i;
            }
        }
        return -1;
    }
}

public class Test {

}
